<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet"
          href="./bootstrap-3.3.7-dist/css/bootstrap.min.css">

    <script src="./bootstrap-3.3.7-dist/js/jquery-3.1.1.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="./bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="./layui/layui.all.js"></script>
    <script src="./js/common.js"></script>
    <script src="https://code.angularjs.org/1.4.0-rc.1/angular.js"></script>
    <style type="text/css">
        body {
            background: url(img/main.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }

        .content {
            margin: 0 auto;
            margin-top: 120px;
            padding: 20px;
            width: 70%;
            height: auto;
            background: #d0d0d0;
            border-radius: 4px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, .04);
            background-color: rgba(255, 255, 255, 0.5)
        }
    </style>
</head>
<body>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-hidden="true">
    <div class="modal-dialog">
        <form class="ticketform">
        <div class="modal-content">

            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">请修改机票信息</h4>
            </div>
            <div class="modal-body">
                <div id="editform">
                    <input type="hidden" name="name"
                           value="lhjun" required>
                    <div class="form-group">
                        <label>姓名</label><input type="text" class="form-control"
                                                id="bookname"
                                                name="bookname" placeholder="姓名" required>
                    </div>
                    <label>性别</label>
                    <div class="radio">
                        <label> <input type="radio" name="booksex"
                                       id="optionsRadios1" value="男" checked required> 男
                        </label>
                    </div>
                    <div class="radio">
                        <label> <input type="radio" name="booksex"
                                       id="optionsRadios2" value="女" required>女
                        </label>
                    </div>

                    <div class="form-group">
                        <label>始发城市</label> <input type="text" class="form-control"
                                                   id="startcity"
                                                   placeholder="始发城市" name="startcity" required>
                    </div>

                    <div class="form-group">
                        <label>目的城市</label> <input type="text" class="form-control"
                                                   id="endcity"
                                                   name="endcity" placeholder="目的城市" required>
                    </div>

                    <div class="form-group">
                        <label>出发日期</label> <input type="date" class="form-control"
                                                   id ="startdate"
                                                   name="startdate" placeholder="出发日期" required>
                    </div>

                    <div class="form-group">
                        <label>身份证</label> <input type="text" class="form-control"
                                                  maxlength="18"
                                                  id="idcard"
                                                  name="idcard" placeholder="身份证" required>
                    </div>
                    <div class="form-group">
                        <label>预定时间</label> <input type="text" class="form-control"
                                                   id="iccid"
                                                   name="iccid" placeholder="预定时间" readonly="readonly">
                    </div>

                    <button class="btn btn-success"
                            id="subbutton"
                            data-dismiss="modal"
                            style="margin-left: 180px; float:left;">提&nbsp;&nbsp;&nbsp;&nbsp;交
                    </button>
                    <button class="btn btn-warning"
                            style="margin-left: 40px; float:left;" data-dismiss="modal">关&nbsp;&nbsp;&nbsp;&nbsp;闭
                    </button>
                    <br>
                    <br>
                </div>
            </div>
        </div>
        </form>
    </div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
<div class="alert alert-info" role="alert">
    <p id="mainhead"></p>
</div>
<button class="btn btn-success" type="submit" style="margin-left: 47%;"
        onclick="window.location.href='/main.html'">回到首页
</button>

<div class="content">
    <button class="btn btn-danger" type="submit" style="margin-left: 47%;"
            id="refresh">刷新
    </button>
    <br/><br/>
    <table class="table table-striped" style="width:100%;" id="listTable">
        <tr>
            <th>订票姓名</th>
            <th>性别</th>
            <th>始发城市</th>
            <th>目的城市</th>
            <th>出发时间</th>
            <th>身份证</th>
            <th>预定时间</th>
            <th>修改</th>
            <th>删除</th>
        </tr>
    </table>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        checklogin();
        loadTicket();
    })

    $('#refresh').click(function (e) {
        checklogin();
        loadTicket();
    })

    $('#subbutton').click(function (e) {
        var bookname = $('#bookname').val();
        var sex = $("input[name='booksex']:checked").val();
        var startcity = $('#startcity').val();
        var endcity = $('#endcity').val();
        var startdate = $('#startdate').val();
        var idcard = $('#idcard').val();
        var iccid = $('#iccid').val();

        var Regx = /^[0-9]*$/;
        if (!Regx.test(idcard)) {
            layer.msg("身份证必须为18位数字")
            return;
        }
        if (idcard.length != 18) {
            layer.msg("身份证必须为18位数字")
            return;
        }
        $.ajax({
            url: '/ticket/update',
            method: 'POST',
            dataType: "json",
            traditional: true,
            data: $(".ticketform").serialize(),
            success: function (data) {
                if (data.status == 'ok') {
                    layer.msg(data.msg);
                    loadTicket();
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function (data) {

            }
        });
    })

</script>
</body>
</html>
